package com.elinkway.infinitemovies.bigdata;

import android.os.Bundle;
import android.text.TextUtils;

import com.elinkway.infinitemovies.async.ReportRealDataTask;

import static com.tencent.qqlive.mediaplayer.config.TencentVideo.getApplicationContext;

/**
 * Created by chengjianlong on 2017/4/24.
 */

public class RealDataApi {

    public static final String SARRS = "sarrs";//业务线
    public static final String SEID = "seid";
    public static final String EXTEND = "extend";
    public static final String KW = "kw";
    public static final String VERSION = "version";
    public static final String ACODE = "acode";
    public static final String OS = "os";
    public static final String APP_NAME = "app_name";
    public static final String UID = "uid";
    public static final String AUID = "auid";
    public static final String NT = "nt";
    public static final String APP = "app";
    public static final String VID = "vid";
    public static final String PID = "pid";
    public static final String CID = "cid";
    public static final String BUCKET = "bucket";
    public static final String CTIME = "ctime";
    public static final String ILU = "ilu";
    public static final String AREA = "area";


    /**
     * @param vid vid信息
     * @param pid 专辑id
     * @param cid 频道id
     * @return
     * @area area表示页面位置，固定传
     * area=rec_0704 相关推荐
     * area=rec_0705 播放结束相关推荐
     * area=rec_0706 下载相关推荐
     * 0703 线上数据
     * 0702 测试数据
     */

    private static void postAction(Bundle bundle, String vid, String pid, String cid) {
        Bundle params = new Bundle();
        params.putString(SARRS, RealDataConfig.getSarrs());
        params.putString(EXTEND, "");
        params.putString(VERSION, BigDataConstants.VERSION);
        params.putString(OS, RealDataConfig.ANDROID_OS);//安卓0 iOS1 iPad2
        params.putString(APP_NAME, BigDataConstants.BD_APP_NAME);
        params.putString(UID, TextUtils.isEmpty(RealDataConfig.getInstance().getUid()) ? "" : RealDataConfig.getInstance().getUid());
        params.putString(AUID, BigDataConstants.AUID);
        params.putString(NT, BigDataUtils.getNetType(getApplicationContext()));
        params.putString(APP, BigDataConstants.VERSION);
        params.putString(VID, vid);
        params.putString(PID, pid);
        params.putString(CID, cid);
        params.putString(CTIME, System.currentTimeMillis() + "");
        params.putString(ILU, TextUtils.isEmpty(RealDataConfig.getInstance().getUid()) ? "1" : "0");
        params.putString(AREA, "");
        params.putAll(bundle);

        new ReportRealDataTask(getApplicationContext(), params).start();

    }

    /**
     * 点击上报
     *
     * @param seid 推荐id、搜索id
     * @param vid  vid信息
     * @param pid  专辑id
     * @param cid  频道id
     */
    public static void RealDataClickReport(String seid, String vid, String pid, String cid,String bucket) {
        Bundle bundle = new Bundle();
        bundle.putString(KW, "");
        bundle.putString(SEID, seid);
        bundle.putString(BUCKET, bucket);
        bundle.putString(ACODE, RealDataConfig.REAL_DATA_ACODE_CLICK);
        postAction(bundle, vid, pid, cid);
    }

    /**
     * 收藏上报
     *
     * @param vid vid信息
     * @param pid 专辑id
     * @param cid 频道id
     */
    public static void RealDataCollectionReport(String vid, String pid, String cid,String seid,String bucket) {
        Bundle bundle = new Bundle();
        bundle.putString(KW, "");
        bundle.putString(SEID, seid);
        bundle.putString(BUCKET, bucket);
        bundle.putString(ACODE, RealDataConfig.REAL_DATA_ACODE_COLLECTION);
        postAction(bundle, vid, pid, cid);

    }

    /**
     * 分享上报
     *
     * @param vid vid信息
     * @param pid 专辑id
     * @param cid 频道id
     */
    public static void RealDataShareReport(String vid, String pid, String cid,String seid,String bucket) {
        Bundle bundle = new Bundle();
        bundle.putString(KW, "");
        bundle.putString(SEID, seid);
        bundle.putString(BUCKET, bucket);
        bundle.putString(ACODE, RealDataConfig.REAL_DATA_ACODE_SHARE);
        postAction(bundle, vid, pid, cid);
    }

    /**
     * 搜索上报
     *
     * @param seid 推荐id、搜索id
     * @param kw   搜索关键字
     */
    public static void RealDataSearchReport(String seid, String kw) {
        Bundle bundle = new Bundle();
        bundle.putString(KW, kw);
        bundle.putString(SEID, seid);
        bundle.putString(BUCKET, "");
        bundle.putString(ACODE, RealDataConfig.REAL_DATA_ACODE_SEARCH);
        postAction(bundle, "", "", "");

    }

}
